const path=require("path"),fs=require("fs");let{rpath,rkey}=require(path.join(__dirname,"/config.bundle")),$=require(path.join(__dirname,"/config.bundle"));module.exports=function(){let a=!1;document.querySelector(".sort__up").addEventListener("click",function(){document.querySelector(".file__context").scrollTop=0}),document.querySelector(".gil__to").addEventListener("dblclick",function(){this.style.display="none",document.querySelector(".gih__to").style.display="flex",document.querySelector("#gih__to").focus()}),document.querySelector(".gil__from").addEventListener("dblclick",function(){this.style.display="none",document.querySelector(".gih__from").style.display="flex",document.querySelector("#gih__from").focus()}),document.querySelector("#gih__to").addEventListener("blur",()=>{for(let a in $.db){let b=Object.keys($.db[a])+"",c=$._fs.getPreset()+"";if(b===c)for(let b in $.db[a])return(document.querySelector(".gih__to").style.display="none",document.querySelector(".gil__to").style.display="flex",""===document.querySelector("#gih__to").value.replace(/\s/g,""))?($._fs.createNotice("\u041F\u043E\u043B\u0435 \u043D\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043F\u0443\u0441\u0442\u044B\u043C"),document.querySelector("#gih__to").value="",!1):($.files_=[],$._fs.cleanActiveList(),document.querySelector(".check__all").removeAttribute("checked"),document.querySelector(".check__all").checked=!1,$.db[a][b].pathTo=document.querySelector("#gih__to").value.trim(),$._fs.setPathTo(document.querySelector("#gih__to").value.trim()),$._fs.updateDB($.db),fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db)),document.querySelector(".home__to").innerHTML=document.querySelector("#gih__to").value.trim(),document.querySelector(".global__to").value=document.querySelector("#gih__to").value,document.querySelector("#gih__to").value="",!1)}}),document.querySelector("#gih__from").addEventListener("blur",()=>{for(let a in $.db){let b=Object.keys($.db[a])+"",c=$._fs.getPreset()+"";if(b===c)for(let b in $.db[a])return(document.querySelector(".gih__from").style.display="none",document.querySelector(".gil__from").style.display="flex",""===document.querySelector("#gih__from").value.replace(/\s/g,""))?($._fs.createNotice("\u041F\u043E\u043B\u0435 \u043D\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043F\u0443\u0441\u0442\u044B\u043C"),document.querySelector("#gih__from").value="",!1):($.files_=[],$._fs.cleanActiveList(),document.querySelector(".check__all").removeAttribute("checked"),document.querySelector(".check__all").checked=!1,$.db[a][b].pathFrom=document.querySelector("#gih__from").value.trim(),$._fs.setPathFrom(document.querySelector("#gih__from").value.trim()),$._fs.updateDB($.db),fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db)),document.querySelector(".home__path").innerHTML=document.querySelector("#gih__from").value.trim(),document.querySelector(".global__from").value=document.querySelector("#gih__from").value,document.querySelector("#gih__from").value="",$._fs.loadFiles(),!1)}}),document.querySelector(".setting-button").addEventListener("click",function(){let a=document.documentElement.getAttribute("theme");"dark"===a?($._fs.setTheme("light"),$.config.theme="light"):($._fs.setTheme("dark"),$.config.theme="dark"),fs.writeFileSync(path.join(__dirname,rpath.config),JSON.stringify($.config))}),document.querySelector(".lang-button").addEventListener("click",function(){let a=document.documentElement.getAttribute("lang");"ru"===a?($._fs.setLang("en"),$.config.lang="en"):($._fs.setLang("ru"),$.config.lang="ru"),fs.writeFileSync(path.join(__dirname,rpath.config),JSON.stringify($.config))}),document.querySelector(".regexp__list").addEventListener("click",function(){const a=this.querySelectorAll("button");if(!a)return!1;let b=[];a.forEach(a=>{a.onclick=()=>{for(let c in $.db){let d=Object.keys($.db[c])+"",e=$._fs.getPreset()+"";if(d===e)for(let d in $.db[c])$.db[c][d].regexp.includes(a.dataset.name)&&(b=$.db[c][d].regexp.filter(b=>b!==a.dataset.name),$.db[c][d].regexp=b)}$._fs.updateRegexp(),$._fs.updateDB($.db),fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db))}})}),document.querySelector(".remember__list").addEventListener("click",function(){const a=this.querySelectorAll("button");if(!a)return!1;let b=[];a.forEach(a=>{a.onclick=()=>{for(let c in $.db){let d=Object.keys($.db[c])+"",e=$._fs.getPreset()+"";if(d===e)for(let d in $.db[c])$.db[c][d].remember.includes(a.dataset.name)&&(b=$.db[c][d].remember.filter(b=>b!==a.dataset.name),$.db[c][d].remember=b)}$._fs.updateRemember(),$._fs.updateDB($.db),fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db))}})}),document.querySelector(".regexp__apply").addEventListener("click",function(){const a=document.querySelector("#global__regexp");if(""===a.value.replace(/\s/g,""))$._fs.createNotice("\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0440\u0435\u0433\u0443\u043B\u044F\u0440\u043D\u043E\u0435 \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u0435");else for(let b in $.db){let c=Object.keys($.db[b])+"",d=$._fs.getPreset()+"";if(c===d)for(let c in $.db[b])$.db[b][c].regexp.includes(a.value)?$._fs.createNotice("\u0422\u0430\u043A\u043E\u0435 \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043D\u043E"):($.db[b][c].regexp.push(a.value),a.value="",$._fs.updateDB($.db),fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db)),$._fs.updateRegexp())}}),document.querySelector(".remember__apply").addEventListener("click",function(){const a=document.querySelector("#global__remember");if(""===a.value.replace(/\s/g,""))$._fs.createNotice("\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u0444\u0430\u0439\u043B");else for(let b in $.db){let c=Object.keys($.db[b])+"",d=$._fs.getPreset()+"";if(c===d)for(let c in $.db[b])$.db[b][c].remember.includes(a.value)?$._fs.createNotice("\u0422\u0430\u043A\u043E\u0439 \u0444\u0430\u0439\u043B \u0437\u0430\u043F\u0438\u0441\u0430\u043D"):($.db[b][c].remember.push(a.value),a.value="",$._fs.updateDB($.db),fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db)),$._fs.updateRemember())}}),document.querySelector(".bth__preset-save").addEventListener("click",function(){let a=document.querySelector("#preset-from"),b=document.querySelector("#preset-to"),c=document.querySelector("#preset-name");if(""!==a.value.replace(/\s/g,"")||""!==b.value.replace(/\s/g,"")||""!==c.value.replace(/\s/g,"")){let d=rkey(20),e=new Map([[`${d}`,{name:c.value,pathFrom:a.value.trim(),pathTo:b.value.trim(),typeFiles:"",sizeFiles:"",wordLeft:"",wordRight:"",changed:"",remember:[],regexp:[]}]]);$.db.push(Object.fromEntries(e)),fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db)),document.querySelector(".preset__list").innerHTML+=`
                    <div class="preset__item-wrap">
                        <label class="preset__item" for="${d}">
                            <input type="radio" name="preset" id="${d}" value="${c.value}"
                            data-from="${a.value}"
                            data-to="${b.value}"
                            data-id="${d}"
                            data-remember=""
                            />
                            <span class="">${c.value}</span>
                        </label>
                        <div>
                            <i class="fa-duotone fa-wrench setting__preset-${d}"></i>
                            ${"start"===d?"":"<i class=\"fa-duotone fa-trash\"></i>"}
                        </div>
                    </div>
                `,document.querySelector(".preset__from-pop").style.display="none",document.querySelector(".preset__from-container").style.display="none",$._fs.updateDB($.db),a.value="",b.value="",c.value=""}}),document.querySelector(".kit__popup").addEventListener("click",function(){const a=this.querySelectorAll(".fa-wrench");return!!a&&void a.forEach(a=>{a.onclick=()=>{let b=a.parentNode.parentNode.querySelector("input"),c={};for(let a in $.db){let d=Object.keys($.db[a])[0]+"";for(let e in $.db[a])if(d===b.dataset.id){c.name=$.db[a][e].name,c.pathFrom=$.db[a][e].pathFrom,c.pathTo=$.db[a][e].pathTo,c.typeFiles=$.db[a][e].typeFiles,c.sizeFiles=$.db[a][e].sizeFiles,c.wordLeft=$.db[a][e].wordLeft,c.wordRight=$.db[a][e].wordRight;break}}document.querySelector("#preset-id").value=b.dataset.id,document.querySelector("#change-name").value=c.name,document.querySelector("#change-from").value=c.pathFrom,document.querySelector("#change-to").value=c.pathTo,document.querySelector("#change-file").value=c.typeFiles,document.querySelector("#change-name-from").value=c.wordLeft,document.querySelector("#change-name-to").value=c.wordRight,document.querySelector("#change-size").value=c.sizeFiles,document.querySelectorAll(".tb__popup").forEach(a=>a.style.display="none"),document.querySelectorAll(".tb__span").forEach(a=>a.classList.remove("tb__bth-active")),document.querySelector(".change__from-pop").style.display="flex",document.querySelector(".change__from-container").style.display="block"}})}),document.querySelector(".bth__change-save").addEventListener("click",function(a){a.preventDefault();let b=document.querySelector("#preset-id").value,c=document.querySelector("#change-name").value,d=document.querySelector("#change-from").value,e=document.querySelector("#change-to").value,f=document.querySelector("#change-file").value,g=document.querySelector("#change-name-from").value,h=document.querySelector("#change-name-to").value,i=document.querySelector("#change-size").value;for(let j in $.db){let a=Object.keys($.db[j])[0]+"";for(let k in $.db[j])if(a===b){$.db[j][k].name=c,$.db[j][k].pathFrom=d.trim(),$.db[j][k].pathTo=e.trim(),$.db[j][k].typeFiles=f,$.db[j][k].sizeFiles=i,$.db[j][k].wordLeft=g,$.db[j][k].wordRight=h,fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db));break}}$._fs.createNotice("\u0414\u0430\u043D\u043D\u044B\u0435 \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u044B"),document.querySelector(".change__from-pop").style.display="none",document.querySelector(".change__from-container").style.display="none",document.querySelector("#preset-id").value="",document.querySelector("#change-name").value="",document.querySelector("#change-from").value="",document.querySelector("#change-to").value="",document.querySelector("#change-file").value="",document.querySelector("#change-name-from").value="",document.querySelector("#change-name-to").value="",document.querySelector("#change-size").value=""}),document.querySelector(".bth__letter-save").addEventListener("click",function(a){a.preventDefault();let b=document.querySelector("#preset__letter-from").value,c=$._fs.getPreset();if(""!==b.replace(/\s/g,""))for(let a in $.db){let d=Object.keys($.db[a])[0]+"";for(let e in $.db[a])if(d===c)return $.db[a][e].pathFrom=b.trim(),document.querySelector("#preset__letter-name").value="",document.querySelector(".preset__letter-pop").style.display="none",document.querySelector(".preset__letter-container").style.display="none",fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db)),$._fs.loadFiles(),!1}}),document.querySelector(".preset__list").addEventListener("click",function(){const a=this.querySelectorAll("input");if(!a)return!1;[].forEach.call(a,a=>{a.onclick=()=>{$.tmpf.id=a.dataset.id,$.tmpf.from=a.dataset.from,$.tmpf.to=a.dataset.to,$.tmpf.remember=a.dataset.remember,$.tmpf.regexp=a.dataset.regexp,$.config.ActivePreset=a.dataset.id,$._fs.setPreset($.tmpf.id,$.tmpf.from,$.tmpf.to,$.tmpf.remember,$.tmpf.regexp),fs.writeFileSync(path.join(__dirname,rpath.config),JSON.stringify($.config)),document.querySelector(".tb__popup").style.display="none"}});const b=this.querySelectorAll(".trash__preset");[].forEach.call(b,a=>{a.onclick=()=>{let b=a.dataset.id,c=$._fs.getPreset(),d=[];if(b===c)$._fs.createNotice("\u0414\u0430\u043D\u043D\u044B\u0439 \u043F\u0440\u0435\u0441\u0435\u0442 \u0430\u043A\u0442\u0438\u0432\u0435\u043D");else{for(let a in $.db){let c=Object.keys($.db[a])+"";c!==b&&d.push($.db[a])}$.db.length=0,$.db.push(...d),$._fs.updateDB($.db),$._fs.updatePreset(),fs.writeFileSync(path.join(__dirname,rpath.db),JSON.stringify($.db))}}})}),document.querySelector(".file__thead input").addEventListener("click",function(){$.files_=[],$._fs.cleanActiveList();let b=this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.querySelectorAll(".file__tbody input"),c=!1;b.forEach(b=>{this.checked?(b.setAttribute("checked","true"),b.checked=!0,c=!0,a=!0):(b.removeAttribute("checked"),b.checked=!1,c=!1,a=!1)}),c?$._fs.getFiles().forEach(a=>{$.files_.push({id:a.id,name:a.name,path:a.path})}):($.files_.length=0,$._fs.cleanActiveList());let d=Object.keys($.files_).length;0<d?(document.querySelector(".search__result").innerHTML=`Выбрано ${$._fs.getCountFiles()} файлов`,document.querySelector(".global__button-tran").style.display="flex"):(document.querySelector(".search__result").innerHTML=`Найдено ${$._fs.getCountFiles()} файлов`,document.querySelector(".global__button-tran").style.display="none")}),document.querySelector(".file__context").addEventListener("contextmenu",function(a){try{let b=a.srcElement.offsetParent.parentNode.querySelector(".context__file .create__props");b.addEventListener("click",function(){let b=a.srcElement.offsetParent.parentNode.querySelector(".file__table-ctx input"),c=new Date(b.dataset.time).toLocaleString("ru",{year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",timezone:"UTC"}),d=new Date(b.dataset.open).toLocaleString("ru",{year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",timezone:"UTC"}),e=new Date(b.dataset.create).toLocaleString("ru",{year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",timezone:"UTC"});document.querySelector(".ino-img").innerHTML=`<img src="${b.dataset.img}" alt="">`,document.querySelector(".ino-name").innerHTML=b.dataset.name,document.querySelector(".ino-path").value=b.dataset.dir,document.querySelector(".ino-type").innerHTML=b.dataset.type,document.querySelector(".ino-size").innerHTML=`${b.dataset.psize} (${b.dataset.size} байт)`,document.querySelector(".ino-create").innerHTML=e,document.querySelector(".ino-changed").innerHTML=c,document.querySelector(".ino-open").innerHTML=d,document.querySelector(".infofile__from-pop").style.display="flex",document.querySelector(".infofile__from-container").style.display="block"}),this.querySelectorAll(".context__file").forEach(a=>a.style.cssText="display:none"),this.querySelectorAll(".file__table-ctx").forEach(a=>a.classList.remove("context__active"));const c=a.pageX,d=a.pageY,e=a.srcElement.offsetParent.parentNode.querySelector(".context__file"),f=a.srcElement.offsetParent.parentNode.querySelector(".file__table-ctx");f.classList.add("context__active");const g=window.innerWidth,h=window.innerHeight;e.style.display="block",e.style.left=g-c<e.offsetWidth?g-e.offsetWidth+"px":c+10+"px",e.style.top=h-d<e.offsetHeight?h-e.offsetHeight+"px":d+15+"px"}catch(a){}}),document.querySelector(".file__context").addEventListener("click",function(b){try{if(!a){const a=b.srcElement.offsetParent.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.querySelectorAll("input");if(!a)return!1;let c=document.querySelector(".file__table input");c.checked&&(c.removeAttribute("checked"),c.checked=!1),$.files_.length=0,a.forEach(a=>{$._fs.cleanActiveList(),a.checked&&$.files_.push({id:a.dataset.id,name:a.dataset.name,path:a.dataset.path})});let d=Object.keys($.files_).length;d===$._fs.getCountFiles()?(document.querySelector(".check__all").setAttribute("checked","true"),document.querySelector(".check__all").checked=!0):(document.querySelector(".check__all").removeAttribute("checked"),document.querySelector(".check__all").checked=!1),0<d?(document.querySelector(".search__result").innerHTML=`Выбрано ${d} файлов`,document.querySelector(".global__button-tran").style.display="flex"):(document.querySelector(".search__result").innerHTML=`Найдено ${$._fs.getCountFiles()} файлов`,document.querySelector(".global__button-tran").style.display="none")}else{let a=b.srcElement.offsetParent.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.querySelectorAll("input"),c=[];a.forEach(a=>{$._fs.cleanActiveList(),a.checked||c.push(a.dataset.path)}),$.files_=$._fs.getFiles().filter(a=>!c.includes(a.path)).map(a=>a);let d=Object.keys($.files_).length;console.log(d+" "+$._fs.getCountFiles()),d===$._fs.getCountFiles()?(document.querySelector(".check__all").setAttribute("checked","true"),document.querySelector(".check__all").checked=!0):(document.querySelector(".check__all").removeAttribute("checked"),document.querySelector(".check__all").checked=!1),0<d?(document.querySelector(".search__result").innerHTML=`Выбрано ${d} файлов`,document.querySelector(".global__button-tran").style.display="flex"):(document.querySelector(".search__result").innerHTML=`Найдено ${$._fs.getCountFiles()} файлов`,document.querySelector(".global__button-tran").style.display="none")}}catch(a){}})};
